'use strict';
const db = uniCloud.database()
const collection = db.collection('houselist')
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('---------------')
	console.log('event内容 : ', event)
	const {pageNum, pageSize} = event
	const {total} = await collection.count()
	// 处理分页
	let res = await collection.skip((pageNum-1) * pageSize).limit(pageSize).get()
	let hasMore = true
	if(pageNum*pageSize > total) {
		hasMore = false
	}
	let result = {
		code: 200,
		hasMore,
		total
	}
	if(res.data.length<=0) {
		result.data = []
	} else {
		result.data = res.data
	}
	//返回数据给客户端
	return result
};
